home *** CD-ROM | disk | FTP | other *** search
- unit ChildMainFormUnit;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls;
-
- type
- TForm1 = class(TForm)
- Memo1: TMemo;
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure Memo1Change(Sender: TObject);
- private
- { Private declarations }
- public
- MemMapFile: THandle;
- MemMapFileBuffer: Pointer;
- end;
-
- {$ifdef Ver90}
- //This exception class did not exist in Delphi 2
- EWin32Error = class(Exception);
- {$endif}
-
- var
- Form1: TForm1;
-
- const
- MemMapFileName = 'SampleMemoryMappedFile';
- MemMapSize = 1000;
-
- implementation
-
- {$R *.DFM}
-
- {$ifdef Ver90}
- //This function class did not exist in Delphi 2
- function Win32Check(RetVal: Bool): Bool;
- var
- LastError: DWord;
- begin
- Result := RetVal;
- if not RetVal then
- begin
- LastError := GetLastError;
- if LastError <> Error_Success then
- raise EWin32Error.CreateFmt( 'Win32 Error. Code: %d.'#10'%s',
- [LastError, SysErrorMessage(LastError)])
- else
- raise EWin32Error.Create('A Win32 API function failed')
- end;
- end;
- {$endif}
-
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- //$FFFFFFFF causes CreateFileMapping to make a shared
- //memory-mapped file which is stored, if
- //it becomes necessary, in the OS swap file
- MemMapFile := CreateFileMapping($FFFFFFFF, nil, Page_ReadWrite, 0,
- MemMapSize, MemMapFileName);
- Win32Check(Bool(MemMapFile));
- MemMapFileBuffer := MapViewOfFile(MemMapFile, File_Map_Write, 0, 0, MemMapSize);
- Win32Check(Bool(MemMapFileBuffer));
- end;
-
- procedure TForm1.FormDestroy(Sender: TObject);
- begin
- CloseHandle(MemMapFile)
- end;
-
- procedure TForm1.Memo1Change(Sender: TObject);
- var
- Msg: String;
- begin
- Msg := Memo1.Text;
- Move(PChar(Msg)^, MemMapFileBuffer^, Length(Msg) + 1)
- end;
-
- end.
-